package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TenderExpertexpertGroup;
import com.ruoyi.system.service.ITenderExpertexpertGroupService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专家组管理Controller
 * 
 * @author ruoyi
 * @date 2025-05-12
 */
@Controller
@RequestMapping("/system/group")
public class TenderExpertexpertGroupController extends BaseController
{
    private String prefix = "system/group";

    @Autowired
    private ITenderExpertexpertGroupService tenderExpertexpertGroupService;

    @Autowired
    private ISysUserService userService;

    @RequiresPermissions("system:group:view")
    @GetMapping()
    public String group()
    {
        return prefix + "/group";
    }

    @GetMapping("/parent")
    public String parent(){
        return prefix + "/parent";
    }

    @PostMapping("/userList")
    @ResponseBody
    public TableDataInfo userList(SysUser user) {
        startPage();
        List<SysUser> list = userService.selectUserList(user);
        return getDataTable(list);
    }

    /**
     * 查询专家组管理列表
     */
    @RequiresPermissions("system:group:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TenderExpertexpertGroup tenderExpertexpertGroup)
    {
        startPage();
        List<TenderExpertexpertGroup> list = tenderExpertexpertGroupService.selectTenderExpertexpertGroupList(tenderExpertexpertGroup);

        return getDataTable(list);
    }

    /**
     * 导出专家组管理列表
     */
    @RequiresPermissions("system:group:export")
    @Log(title = "专家组管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TenderExpertexpertGroup tenderExpertexpertGroup)
    {
        List<TenderExpertexpertGroup> list = tenderExpertexpertGroupService.selectTenderExpertexpertGroupList(tenderExpertexpertGroup);
        ExcelUtil<TenderExpertexpertGroup> util = new ExcelUtil<TenderExpertexpertGroup>(TenderExpertexpertGroup.class);
        return util.exportExcel(list, "专家组管理数据");
    }

    /**
     * 新增专家组管理
     */
    @RequiresPermissions("system:group:add")
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        List<SysUser> sysUsers = userService.selectAllUser();
        mmap.put("posts",sysUsers );
        return prefix + "/add";
    }

    /**
     * 新增保存专家组管理
     */
    @RequiresPermissions("system:group:add")
    @Log(title = "专家组管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TenderExpertexpertGroup tenderExpertexpertGroup)
    {
        return toAjax(tenderExpertexpertGroupService.insertTenderExpertexpertGroup(tenderExpertexpertGroup));
    }

    /**
     * 修改专家组管理
     */
    @RequiresPermissions("system:group:edit")
    @GetMapping("/edit/{groupId}")
    public String edit(@PathVariable("groupId") Long groupId, ModelMap mmap)
    {
        TenderExpertexpertGroup tenderExpertexpertGroup = tenderExpertexpertGroupService.selectTenderExpertexpertGroupByGroupId(groupId);
        mmap.put("tenderExpertexpertGroup", tenderExpertexpertGroup);
        List<SysUser> sysUsers = userService.selectAllUser();
        mmap.put("posts",sysUsers );
        return prefix + "/edit";
    }

    /**
     * 修改保存专家组管理
     */
    @RequiresPermissions("system:group:edit")
    @Log(title = "专家组管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TenderExpertexpertGroup tenderExpertexpertGroup)
    {
        return toAjax(tenderExpertexpertGroupService.updateTenderExpertexpertGroup(tenderExpertexpertGroup));
    }

    /**
     * 删除专家组管理
     */
    @RequiresPermissions("system:group:remove")
    @Log(title = "专家组管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tenderExpertexpertGroupService.deleteTenderExpertexpertGroupByGroupIds(ids));
    }
}
